/* 
 * UNIVERSIDADE FEDERAL DO RIO GRANDE DO NORTE
 * CENTRO DE TECNOLOGIA
 * DEPARTAMENTO DE ENGENHARIA DE COMPUTA��O E AUTOMA��O
 * PROJETO E DESENVOLVIMENTO DE SOFTWARE
 * 
 * BACO SYSTEM
 * CLASSE: PersistenciaServidorOPC
 * VERS�O ORIGINAL: Caroline Albuquerque Dantas Silva
 * MODIFICA��ES: ---
 * */

package bacoopc.persistencia;

import bacoopc.ConexaoOPC;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class PersistenciaServidorOPC extends Persistencia
{
	public PersistenciaServidorOPC()
	{
		super();
	}
	
	//por favor, passar o objeto "servidor"
	public int inserirServidorOPC( ConexaoOPC conexao ) {
		QueryManager manager = QueryManager.getQueryManager();
		
		try 
		{
			PreparedStatement ps = manager.getPreparedStatement(con, "servidor.insert");
			ps.setString( 1 , conexao.getNome() );
			ps.setString( 2 , conexao.getHost() ) ;
			return ps.executeUpdate();
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}		
		return 0;
	}
	
	//por favor, passar o objeto "servidor"
	public int excluirServidorOPC(int id)
	{
		QueryManager manager = QueryManager.getQueryManager();
		
		try 
		{
			PreparedStatement ps = manager.getPreparedStatement(con, "servidor.delete");
			ps.setInt(1, id);
			return ps.executeUpdate();
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}		
		return 0;
	}

	//por favor, passar o objeto "servidor"
	public int alterarServidorOPC(int id, String name, int port, int status, int tempflag)
	{
		QueryManager manager = QueryManager.getQueryManager();
		
		try 
		{
			PreparedStatement ps = manager.getPreparedStatement(con, "servidor.update");
			ps.setString(1, name);
			ps.setInt(2, port);
			ps.setInt(3, status);
			ps.setInt(4, tempflag);
			ps.setInt(5, id);
			return ps.executeUpdate();
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}		
		return 0;
	}

        public ResultSet consultarServidores()
	{
		QueryManager manager = QueryManager.getQueryManager();

		try
		{
			PreparedStatement ps = manager.getPreparedStatement(con, "servidor.query");
			return ps.executeQuery();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
}
